package dao

import (
	. "Gin/app/model"
	. "Gin/utils/Mysql"
	"fmt"
	"log"
)

type RootDao struct {
}

func (rd *RootDao) FindRootById(id int) *Root {
	r := &Root{}
	sql := "select * from root where id = ?"
	err := Db.QueryRow(sql, id).
		Scan(&r.Id, &r.Root, &r.Password, &r.Ip, &r.Times, &r.CreateTime, &r.UpdateTime)
	if err != nil {
		panic(fmt.Sprintf("查询错误:%s\n", err.Error()))
	}
	return r
}

func (rd *RootDao) FindRootByName(username string) *Root {
	r := &Root{}
	sql := "select * from root where root = ?"
	err := Db.QueryRow(sql, username).
		Scan(&r.Id, &r.Root, &r.Password, &r.Ip, &r.Times, &r.CreateTime, &r.UpdateTime)
	if err != nil {
		log.Println("查询出错")
		return nil
	}
	return r
}
